package com.gzxx.security;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * @author MAX
 * @date 2020/7/23 6:18 下午
 * 自定义认证用户
 */

@Data
public class CurrentUser implements UserDetails {

    private static final long serialVersionUID = 7685433730649830096L;

    private Long id;
    private String userAccount;
    private String userPassword;
    private Boolean accountStatus;

    private String employeeName;

    private Integer roleId;

    private Collection<SimpleGrantedAuthority> authorities;
    private List<String> permissions;


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @Override
    public String getPassword() {
        return this.userPassword;
    }

    @Override
    public String getUsername() {
        return this.userAccount;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return !this.accountStatus;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return !this.accountStatus;
    }
}
